package cn.wit.luohui.day11;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.junit.Test;

//源代码的编码会影响我们字符流的默认编码

//不管源代码是什么编码，我们都可以通过手动指定输入流的编码来正确的读取文件
public class DemoReader {
	@Test
	public void test() {

		String path = "E:\\毒鸡汤.txt";
		try (InputStreamReader is = new InputStreamReader(new FileInputStream(path), "utf-8")

		) {
			char[] chars = new char[1024];

			int count = 0;
			while ((count = is.read(chars)) != -1) {
				System.out.println(new String(chars, 0, count));
			}

		} catch (IOException e) {

			e.printStackTrace();
		}
	}

}
